package com.xbongbong.saas.model.impl;

import com.xbongbong.saas.domain.dao.DingBundleUserDao;
import com.xbongbong.saas.domain.entity.DingBundleUserEntity;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.saas.model.DingBundleUserModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author chenshan
 * @version v1.0
 * @since 2019-08-16 10:50
 */
@Service("dingBundleUserModel")
public class DingBundleUserModelImpl implements DingBundleUserModel {
    
    @Resource
    private DingBundleUserDao dingBundleUserDao;
    
    @Override
    public Integer insert(DingBundleUserEntity entity) {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return dingBundleUserDao.insert(entity);
    }
    
    @Override
    public void insertBatch(List<DingBundleUserEntity> dingBundleUserList) {
        dingBundleUserDao.insertBatch(dingBundleUserList);
    }
    
    @Override
    public Integer save(DingBundleUserEntity entity) {
        if ( entity.getId() == null || entity.getId().equals(0L) ) {
            return insert(entity);
        }
        return update(entity);
    }
    
    @Override
    public Integer update(DingBundleUserEntity entity) {
        long now = DateUtil.getInt();
        entity.setUpdateTime(now);
        return dingBundleUserDao.update(entity);
    }
    
    @Override
    public DingBundleUserEntity getEntity(Long id, String corpid) {
        return dingBundleUserDao.getByKey(id, corpid);
    }
    
    @Override
    public Integer deleteByIds(List<Long> ids, String corpid) {
        return dingBundleUserDao.deleteByIdIn(ids,corpid);
    }
    @Override
    public Integer deleteByOpenConversationId(String openConversationId, String corpid){
        return dingBundleUserDao.deleteByOpenConversationId(openConversationId,corpid);
    }
    @Override
    public List findEntitys(Map<String, Object> param) {
        return dingBundleUserDao.findEntitys(param);
    }
    
    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dingBundleUserDao.getEntitysCount(param);
    }
    
    /**
     * Description: 查询符合条件的数据（无子表单数据）
     *
     * @param param
     * @return java.util.List<T>
     * @throws
     * @author 魏荣杰
     * @date 2020/10/13 16:07
     * @since
     */
    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }
    
    @Override
    public void updateBatch(List<DingBundleUserEntity> dingBundleUserList) {
        dingBundleUserDao.updateBatch(dingBundleUserList);
    }
    
    @Override
    public void deleteByBundleAndUserIds(String corpid, Long bundleId, List<String> userIds) {
        dingBundleUserDao.deleteByBundleAndUserIds(corpid,bundleId,userIds);
    }
    
    @Override
    public void updateBatchSubAdmin(String corpid, String openConversationId, List<String> userIds) {
        dingBundleUserDao.updateBatchSubAdmin(corpid,openConversationId,userIds);
    }

    @Override
    public Integer dataConsistencyUpdateUser(String corpid, String userId, String name, String avatar) {
        return dingBundleUserDao.dataConsistencyUpdateUser(corpid, userId, name, avatar);
    }
}